<template>
  <div class="login-container">
    <video autoplay loop muted src="https://slwl-admin.itheima.net/static/media/video.3cf57b17.mp4" />
    <div class="form">
      <div class="title-container">
        <img src="https://slwl-admin.itheima.net/static/img/logo1.33ef7fa0.png" alt="" class="title-image">
      </div>
      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="loginForm" :model="loginForm" :rules="rules">

          <el-form-item prop="account">
            <el-input v-model="loginForm.account" placeholder="请输入用户名" prefix-icon="el-icon-user-solid" />

          </el-form-item>

          <el-form-item prop="password">
            <el-input v-model="loginForm.password" type="password" placeholder="请输入密码" show-password prefix-icon="el-icon-unlock" />
          </el-form-item>

          <el-form-item prop="code" class="code-image-box">
            <img :src="img" alt="" class="code-image" @click="changeCode">
            <el-input v-model="loginForm.code" placeholder="验证码" prefix-icon="el-icon-unlock" />
          </el-form-item>

          <el-form-item class="changeColor">
            <el-button style="width:350px" @click="hlogin">登录</el-button>
          </el-form-item>
        </el-form>
        <div class="gentleReminder">
          仅用于IT培训教学使用，为保障您的个人信息安全，请勿向平台录入任何个人敏感信息（如手机号、身份证号等）！
        </div>
      </el-card>
    </div>
  </div>
</template>
<script>
import { code } from '@/api/user'
import { randomNum } from '@/utils'
export default {
  name: 'Login',
  data() {
    return {
      loginForm: {
        account: 'shenlingadmin',
        password: '123456',
        code: '',
        key: randomNum(24, 16),
        tenant: '',
        bindAccount: '',
        bindPassword: '',
        signAccount: '',
        signPassword: ''
      },
      rules: {
        mobile: [
          { required: true, message: '手机号不能为空', trigger: 'blur' },
          { min: 5, max: 16, message: '长度在 5 到 16 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '密码不能为空', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '验证码不能为空', trigger: 'blur' }
        ]
      },
      img: ''
    }
  },
  // 进入登录页就发送请求获取数据
  async created() {
    // 获取验证码
    this.getcode()
  },
  methods: {
    hlogin() {
      // 兜底校验 validate (  官方文档 )
      this.$refs.loginForm.validate((valid) => {
        console.log(valid)
        valid && this.sendLogin()
      })
    },
    // 请求函数
    async sendLogin() {
      // 发送登录请求
      await this.$store.dispatch('user/login', this.loginForm)
      this.$router.push('/')
      this.$message.success('登录成功')
    },
    // 获取验证码函数
    async getcode() {
      const res = await code(this.loginForm.key)
      console.log(res.data)
      this.img = window.URL.createObjectURL(new Blob([res.data]))
    },
    // 点击切换验证码
    changeCode() {
      this.getcode()
    }
  }
}
</script>
<style lang="scss">
.login-container {
    background-size: 100% 100%;
    height: 100vh;
    overflow-y: hidden;
    position: relative;
  video{
      position: fixed;
      right: 0px;
      bottom: 0px;
      min-width: 100%;
      min-height: 100%;
      height: auto;
      width: auto;
      /*加滤镜*/
      /*filter: blur(15px); //背景模糊设置 */
      /*-webkit-filter: grayscale(100%);*/
      /*filter:grayscale(100%); //背景灰度设置*/
      z-index:-11
   }
   .gentleReminder{
    line-height: 20px;
    font-size: 14px;
    color: #fd3333;
    // margin-bottom: 20px
   }
 .form {
   position: absolute;
      top: 45%;
      left: 45%;
      margin: -180px 0 0 -160px;
      width: 450px;
      height: 490px;
      padding: 30px 40px;
      background: #fff;
      border-radius: 10px;
     .title-container {
      text-align: center;
      .title-image {
        height: 54px;
      }
      }
    .el-card {
      border: none;
      padding: 0;
    }
    .el-input {
      width: 350px;
      height: 44px;
      .el-input__inner {
        background: #f4f5fb;
      }
    }
    .el-checkbox {
      color:#606266;
    }
    .changeColor button {
    width: 100%;
    height: 54px;
    margin-bottom: 12px;
    margin-top: 22px;
    background-color: #e15536;
    border: 0;
    font-size: 18px;
    color: #fff;
    font-weight: 700;
    }
    .code-image-box {
      .code-image{
        display: inline-block;
        vertical-align: top;
        width: 71px;
        height: 32px;
        cursor: pointer;
        margin-left: 10px;
        position: absolute;
        right: 10px;
        top: 4px;
        background: #fff;
        z-index: 99;
        }
    }
  }
}

</style>
